﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets; 

namespace TCPClient{
    class Connector
    {
        private const String IP = "85.214.103.114";
        private const int PORT = 110;
        private const String MESSAGE = "MKI"; 

        private TcpClient client ; 
    
        public Connector(){
            client = new TcpClient();
            client.Connect(IP, PORT);
            if (client.Connected)
                System.Console.WriteLine("Connection to server established"); 
            Sender sender = new Sender(client);
            Receiver receiver = new Receiver(client);
            for (int i = 0; i < 10; i++)
            {
                System.Console.WriteLine("Sending message:\n-----------------------------\n " + MESSAGE); 
                sender.send(MESSAGE);
                String response = "" ;
                while (response == null || response == "" || response.Length == 0) response = receiver.receive().Trim() ;
                System.Console.WriteLine("Received message from server: \n-----------------------------\n"+response);
            }
            return; 
        }

    }
}